import React from 'react';
import {Button,Select,DatePicker,Table,Message,Form} from 'antd';
import {hashHistory} from 'react-router';
let FormItem = Form.Item;
let love = React.createClass({
    getInitialState(){
      return{
        state:true,
        amount:0,
        rest:0,
        type:'2',
        dateRange:[],
        data:[],
        page:{current:1,total:0,pageSize:6},
      };
    },
    componentDidMount(){
      let self = this;
      Utils.sendAjax({
        url:'/funder/accout/info',
        callback:function(result){
          if(result.code=='200'){
            self.setState({
              rest:result.data.bscAccount,
              amount:result.data.monthArrival
            });
          }
        }
      });
     this.handle(this.state.page);
    },
    submit(){
      let page = {type:true,current:this.state.current};
      this.handle(page);
    },
    typeChange(value){
      this.setState({
        type:value
      });
    },
    checkCondition(data){//检查查询条件
      let self = this;
      if(self.state.dateRange.length>0){
        data.startTime = self.state.dateRange[0];
        data.endTime = self.state.dateRange[1];
      }
      if(self.state.type!='2'){
        data.paymentState = self.state.type;
      }
    },
    handle(pagination){
      console.log(pagination);
      let self = this;
      let data = {
        currentPage:pagination.current,
        pageSize:self.state.page.pageSize
      };
      if(pagination.type){
        data.currentPage=1;
      }
      this.checkCondition(data);
      Utils.sendAjax({
        url:'/funder/cash/findList',
        data:JSON.stringify(data),
        callback:function(result){
          if(result.code=='200'){
            if(result.page.total>50){
              size = 12;
            }else{
              size = 6;
            }
            self.setState({
              data:result.data,
              page:{
                current:result.page.currentPage,
                total:result.page.total,
                pageSize:size
              }
            });
          }
        }
      });
    },
    dateChange(date,dateString){
      this.setState({
        dateRange:dateString
      });
    },
    reset(){
      this.setState({
        type:'2',
        dateRange:[],
      });
    },
    toGetCash(){
        hashHistory.push('/funder/fundRest/getCash');
    },
    render(){
      const Option = Select.Option;
      const RangePicker = DatePicker.RangePicker;
      const Columns =[ {
         title:'申请时间',
         dataIndex:'applyTime',
         key:'applyTime'
      },{
        title:'提现金额',
        dataIndex:'amount',
        key:'amount'
      },{
        title:'开户行',
        dataIndex:'bankBranch',
        key:'bankBranch'
      },{
        title:'银行卡号',
        dataIndex:'bankNo',
        key:'bankNo'
      },{
        title:'手续费',
        dataIndex:'deductAmount',
        key:'deductAmount'
      },{
        title:'提现结果',
        dataIndex:'paymentState',
        key:'paymentState',
        render:(text,record,index)=>{
            if(text==1){
              return '成功';
            }else if (text==3){
              return '驳回';
            }else{
              return '处理中';
            }
        }
      }];
      // const data = [{
      //   key:'1',
      //   applyTime:'2017-3-28 9:57:30',
      //   amount:'2000.00',
      //   bankName:'中国银行',
      //   bankNo:'231543218248431531',
      //   fee:'2.00',
      //   result:'成功'
      // }];
      return (
        <div>
        <div className='getCash-title'>资金提现</div>
        <div className='basicInfo'>
          <div className='basicItem'>
             <i className='restIconBasic restIcon1' />
             <div>
               <div><font>{this.state.amount}</font><font>元</font></div>
               <div><font>本月到款</font>(可提现)</div>
             </div>
          </div>
          <div className='basicItem'>
             <i className='restIconBasic restIcon2' />
             <div>
               <div><font>{this.state.rest}</font><font>元</font></div>
               <div><font>账户余额</font></div>
             </div>
          </div>
          <div className='basicItem'><Button type='primary' onClick={this.toGetCash}>立即提现</Button></div>
        </div>
        <div className='formList'>
           <div className='formHeader'>
           <Form inline>
            <FormItem label='交易类型'>
                <Select value={this.state.type} onChange={this.typeChange} style={{width:'162px'}}>
                <Option value='1'>成功</Option>
                <Option value='3'>驳回</Option>
                <Option value='0'>处理中</Option>
                <Option value='2'>全部</Option>
                </Select>
                </FormItem>
                <FormItem label='日期范围'>
                <RangePicker onChange={this.dateChange} value={this.state.dateRange}/>
                </FormItem>
                <FormItem>
             <div className='submitForm'>
               <Button type='primary' onClick={this.submit}>查 询</Button>
               <Button type='primary' onClick={this.reset}>重 置</Button>
             </div>
             </FormItem>
             </Form>
           </div>
           <div className='formBody'>
             <Table columns={Columns} dataSource={this.state.data} onChange={this.handle} pagination={this.state.page} rowKey={(record)=>(record.id)}/>
           </div>
        </div>
        </div>
      )
    }
});

export default love;
